<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="项目报备单号" prop="reportNum">
        <el-input
          v-model="queryParams.reportNum"
          placeholder="请输入项目报备单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进场时间" prop="entryTime">
        <el-date-picker clearable
          v-model="queryParams.entryTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择进场时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['check:entryReport:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['check:entryReport:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['check:entryReport:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['check:entryReport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="entryReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="进场上报id" align="center" prop="entryReportId" width="110" fixed/>
      <el-table-column label="项目报备单号" align="center" prop="reportNum" width="120" fixed/>
      <el-table-column label="项目名称" align="center" prop="projectName" width="200" fixed/>
      <el-table-column label="进场时间" align="center" prop="entryTime" width="100" fixed>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否占道" align="center" prop="isJeeves" fixed >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isJeeves"
            :active-value = '1'
            :inactive-value = '0'
            disabled
          ></el-switch>
        </template>
      </el-table-column>

      <el-table-column label="占道信息">
          <el-table-column label="占道长度/米" align="center" prop="jeevesLength" width="90" />
          <el-table-column label="占道宽度/米" align="center" prop="jeevesWidth" width="90" />
          <el-table-column label="占道开始时间" align="center" prop="jeevesStartDate" width="120">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.jeevesStartDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="占道截止时间" align="center" prop="jeevesEndDate" width="120">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.jeevesEndDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
      </el-table-column>

      <el-table-column label="施工路段">
          <el-table-column label="施工开始路段" align="center" prop="expresswayStartSectionName"  width="120"/>
          <el-table-column label="施工结束路段" align="center" prop="expresswayEndSectionName"  width="120"/>
          <el-table-column label="施工开始方向" align="center" prop="jeevesStartDirection"  width="100">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.business_cons_direction_type" :value="scope.row.jeevesStartDirection"/>
            </template>
          </el-table-column>
          <el-table-column label="施工结束方向" align="center" prop="jeevesEndDirection"  width="100">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.business_cons_direction_type" :value="scope.row.jeevesEndDirection"/>
            </template>
          </el-table-column>
          <el-table-column label="占道开始桩号" align="center" prop="jeevesStartPile"  width="100"/>
          <el-table-column label="占道结束桩号" align="center" prop="jeevesEndPile"  width="100"/>
      </el-table-column>
      <el-table-column label="道路名称" align="center" prop="roadName" width="150" :show-overflow-tooltip='true'/>
      <el-table-column label="方向" align="center" prop="direction" />

      <el-table-column label="创建人" align="center" prop="createByName" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="100"  >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属管辖大队" align="center" prop="deptName"  width="100"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['check:entryReport:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['check:entryReport:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row,scope.index)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改进场上报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="项目报备单号" prop="reportInfoId">
              <el-select v-model="form.reportInfoId" filterable placeholder="请选项目报备单号" style="width: 100%"
                         @change="handleChange" :disabled="this.disabledSelectReportInfo" >
                <el-option
                  v-for="item in reportInfoOption"
                  :key="item.reportInfoId"
                  :label="item.reportNum"
                  :value="item.reportInfoId">
                  <span style="float: left">{{ item.reportNum }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.projectName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进场时间" prop="entryTime">
              <el-date-picker clearable
                              v-model="form.entryTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              style="width: 200px"
                              placeholder="请选择进场时间"
                              :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否占道" prop="isJeeves">
              <el-switch
                v-model="form.isJeeves"
                :active-value= 1
                :inactive-value= 0>
              </el-switch>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="占道长度" prop="jeevesLength" v-if="form.isJeeves == 1">
              <el-input v-model="form.jeevesLength" placeholder="请输入占道长度" >
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px; color: #1e1e1e">米</i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="占道宽度" prop="jeevesWidth" v-if="form.isJeeves == 1">
              <el-input v-model="form.jeevesWidth" placeholder="请输入占道宽度" >
                <i slot="suffix" style="font-style:normal;margin-right: 10px; line-height: 30px; color: #1e1e1e">米</i>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="占道起止日期" prop="dateRange" v-if="form.isJeeves == 1">
              <el-date-picker
                v-model="form.dateRange"
                style="width: 200px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="施工起止时段" prop="timeRange" v-if="form.isJeeves == 1">
              <el-time-picker
                style="width: 200px"
                is-range
                value-format="HH:mm:ss"
                arrow-control
                v-model="form.timeRange"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                placeholder="选择时间范围">
              </el-time-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="施工开始路段" prop="expresswayStartSectionId" v-if="form.isJeeves == 1" >
              <el-select v-model="form.expresswayStartSectionId" filterable placeholder="请选择施工开始路段" style="width: 100%">
                <el-option
                  v-for="item in expresswaySectionOption"
                  :key="item.expresswaySectionId"
                  :label="item.expresswaySectionName + item.startStation +'至'+ item.endStation"
                  :value="item.expresswaySectionId">
                </el-option>
              </el-select>
            </el-form-item>

          </el-col>
          <el-col :span="8">
            <el-form-item label="施工开始方向" prop="jeevesStartDirection" v-if="form.isJeeves == 1">
              <el-select v-model="form.jeevesStartDirection" placeholder="请选择施工开始方向">
                <el-option
                  v-for="dict in dict.type.business_cons_direction_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="占道开始桩号" prop="jeevesStartPile" v-if="form.isJeeves == 1">
              <el-input v-model="form.jeevesStartPile" placeholder="请输入占道开始桩号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="施工结束路段" prop="expresswayEndSectionId" v-if="form.isJeeves == 1">
              <el-select v-model="form.expresswayEndSectionId" filterable placeholder="请选施工结束路段" style="width: 100%">
                <el-option
                  v-for="item in expresswaySectionOption"
                  :key="item.expresswaySectionId"
                  :label="item.expresswaySectionName + item.startStation +'至'+ item.endStation"
                  :value="item.expresswaySectionId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工结束方向" prop="jeevesEndDirection" v-if="form.isJeeves == 1">
              <el-select v-model="form.jeevesEndDirection" placeholder="请选择施工结束方向">
                <el-option
                  v-for="dict in dict.type.business_cons_direction_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="占道结束桩号" prop="jeevesEndPile" v-if="form.isJeeves == 1">
              <el-input v-model="form.jeevesEndPile" placeholder="请输入占道结束桩号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="现场照片及视频" prop="entryFile">
              <file-upload  @input="getFileList" :fileLocationName="'entryFile'" :value="this.entryFileData" :fileType="['jpeg','png','jpg','video','mp4']" :limit="5" :fileSize="50"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注内容" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="所属管辖大队" prop="deptName">
              <el-input v-model="form.deptName" placeholder="所属管辖大队" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="联系人" prop="deptLeader">
              <el-input v-model="form.deptLeader" placeholder="联系人" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="deptPhone">
              <el-input v-model="form.deptPhone" placeholder="联系电话" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看进场上报对话框 -->
    <el-dialog :title="title" :visible.sync="viewOpen" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="项目报备单号：">{{ form.reportNum }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进场时间：">{{ parseTime(form.entryTime, '{y}-{m}-{d}') }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否占道：">{{ form.isJeeves == 1 ? '是':'否'}}</el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="form.isJeeves == 1">
          <el-col :span="8">
            <el-form-item label="占道长度：">{{ form.jeevesLength + '米'}}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="占道宽度：">{{ form.jeevesWidth + '米'}}</el-form-item>
          </el-col>

        </el-row>
        <el-row v-if="form.isJeeves == 1">
          <el-col :span="8">
            <el-form-item label="占道起止日期：">{{ form.jeevesStartDate + '至' + form.jeevesEndDate}}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工起止时段：">{{ form.consStartTime + '至' + form.consEndTime}}</el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.isJeeves == 1">
          <el-col :span="8">
            <el-form-item label="施工开始路段：">{{ form.expresswayStartSectionName }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工开始方向：">
              <dict-tag :options="dict.type.business_cons_direction_type" :value="form.jeevesStartDirection"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="占道开始桩号：">{{ form.jeevesStartPile }}</el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="form.isJeeves == 1">
          <el-col :span="8">
            <el-form-item label="施工结束路段：">{{ form.expresswayEndSectionName }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施工结束方向：">
              <dict-tag :options="dict.type.business_cons_direction_type" :value="form.jeevesEndDirection"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="占道结束桩号：">{{ form.jeevesEndPile }}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="现场照片及视频" prop="entryFile">
              <image-preview  :value="this.entryFileData" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注内容：">{{ form.remark }}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="经纬度：">{{ form.longitude + ',' + form.latitude}}</el-form-item>-->
<!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="道路名称：">{{ form.roadName }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="方向：">{{ form.direction }}</el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="所属管辖大队：">{{ form.deptName }}</el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="联系人：">{{ form.deptLeader }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话：">{{ form.deptPhone }}</el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listEntryReport, getEntryReport, delEntryReport, addEntryReport, updateEntryReport } from "@/api/check/entryReport";
import { deptUserTreeSelect } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { selectListreportInfo} from "@/api/check/reportInfo";
import { selectListExpresswaySection } from "@/api/check/expresswaySection";
export default {
  name: "EntryReport",
  components: { Treeselect },
  dicts: ['business_cons_direction_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 进场上报表格数据
      entryReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportNum: '',
        entryTime: null,
      },
      // 表单参数
      form: {},
      // 日期范围
      //dateRange: [],
      //  组织部门
      deptOptions: undefined,

      //  报备信息option
      reportInfoOption:[],

      //  高速路段option
      expresswaySectionOption:[],

      //  现场照片及视频
      entryFileData:[],

      //  禁用项目报备下拉列表选项 默认开启
      disabledSelectReportInfo : false,

      //  是否显示详情弹出层
      viewOpen: false,

      // 表单校验
      rules: {
        reportInfoId: [
          { required: true, message: "项目报备id不能为空", trigger: "blur" }
        ],
        entryTime: [
          { required: true, message: "进场时间不能为空", trigger: "blur" }
        ],
        isJeeves: [
          { required: true, message: "是否占道 (0否 1是)不能为空", trigger: "blur" }
        ],
        jeevesLength: [
          { required: true, message: "占道长度不能为空", trigger: "blur" }
        ],
        jeevesWidth: [
          { required: true, message: "占道宽度不能为空", trigger: "blur" }
        ],
        dateRange: [
          {
            type: 'array',
            required: true,
            message: '请选择日期区间',
            fields: {
              // tpye类型试情况而定,所以如果返回的是date就改成date,如果返回的是string就改成string
              0: { type: 'string', required: true, message: '请选择开始日期' },
              1: { type: 'string', required: true, message: '请选择结束日期' },
            },
          },
        ],
        timeRange: [
          {
            type: 'array',
            required: true,
            message: '请选择施工起止时段',
            fields: {
              // tpye类型试情况而定,所以如果返回的是date就改成date,如果返回的是string就改成string
              0: { type: 'string', required: true, trigger: "change",message: '请选择施工起止时段' },
              1: { type: 'string', required: true, trigger: "change",message: '请选择施工起止时段' },
            },
          },
        ],
        jeevesEndTime: [
          { required: true, message: "占道截止时间不能为空", trigger: "blur" }
        ],
        expresswayStartSectionId: [
          { required: true, message: "施工开始路段不能为空", trigger: "blur" }
        ],
        expresswayEndSectionId: [
          { required: true, message: "施工结束路段不能为空", trigger: "blur" }
        ],
        jeevesStartDirection: [
          { required: true, message: "施工开始方向不能为空", trigger: "change" }
        ],
        jeevesEndDirection: [
          { required: true, message: "施工结束方向不能为空", trigger: "change" }
        ],
        jeevesStartPile: [
          { required: true, message: "占道开始桩号不能为空", trigger: "blur" }
        ],
        jeevesEndPile: [
          { required: true, message: "占道结束桩号不能为空", trigger: "blur" }
        ],
        longitude: [
          { required: true, message: "经度不能为空", trigger: "blur" }
        ],
        latitude: [
          { required: true, message: "纬度不能为空", trigger: "blur" }
        ],
        roadName: [
          { required: true, message: "道路名称不能为空", trigger: "blur" }
        ],
      },
      pickerOptions: {
        disabledDate: (time) => {
          let nowData = new Date()
          nowData = new Date(nowData.setDate(nowData.getDate() - 1))
          return time < nowData
        }
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询进场上报列表 */
    getList() {
      this.loading = true;
      listEntryReport(this.queryParams).then(response => {
        this.entryReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        entryReportId: null,
        reportInfoId: null,
        entryTime: null,
        isJeeves: null,
        jeevesLength: null,
        jeevesWidth: null,
        jeevesStartTime: null,
        jeevesEndTime: null,
        expresswayStartSectionId: null,
        expresswayEndSectionId: null,
        jeevesStartDirection: null,
        jeevesEndDirection: null,
        jeevesStartPile: null,
        jeevesEndPile: null,
        entryFileId: null,
        remark: null,
        longitude: null,
        latitude: null,
        roadName: null,
        direction: null,
        deptId: null,
        reviewedBy: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
      this.entryFileData = null;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.entryReportId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加进场上报";
      //  报备下拉列表启用
      this.disabledSelectReportInfo = false;
      //this.getDeptTree();
      //是否占道  默认否
      this.form.isJeeves = 0 ;
      this.getReportInfoList();
      this.getExpresswaySectionList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const entryReportId = row.entryReportId || this.ids
      getEntryReport(entryReportId).then(response => {
        this.form = response.data;
        //日期区间回显
        if(this.form.isJeeves == 1){
          this.$set(this.form, 'dateRange', [response.data.jeevesStartDate, response.data.jeevesEndDate]);
          this.$set(this.form, 'timeRange', [response.data.consStartTime, response.data.consEndTime]);
        }
        this.open = true;
        this.title = "修改进场上报";
        //  报备下拉列表禁用
        this.disabledSelectReportInfo = true;
        //this.getDeptTree();
        this.getReportInfoList();
        this.getExpresswaySectionList();
        this.entryFileData = response.data.entryFile;
      });
    },

    /** 详情按钮操作 */
    handleView(row) {
      this.reset();
      const entryReportId = row.entryReportId || this.ids
      getEntryReport(entryReportId).then(response => {
        this.form = response.data;
        this.viewOpen = true;
        this.title = "查看进场上报";
        this.entryFileData = response.data.entryFile;
      });
    },

    /** 提交按钮 */
    submitForm() {
      if(this.form.isJeeves == 1){
        this.$refs["form"].validate(valid => {
          if (valid) {
            //组装 占道日期时间段数据
            this.form.jeevesStartDate = this.form.dateRange[0];
            this.form.jeevesEndDate = this.form.dateRange[1];
            this.form.consStartTime = this.form.timeRange[0];
            this.form.consEndTime = this.form.timeRange[1];
            if (this.form.entryReportId != null) {
              updateEntryReport(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addEntryReport(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      }else{
        if(!this.form.reportInfoId){
          this.$modal.msgError("请选择项目报备单号!");
          return;
        }
        if(!this.form.entryTime){
          this.$modal.msgError("请选择进场时间!");
          return;
        }
        if (this.form.entryReportId != null) {
          updateEntryReport(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        } else {
          addEntryReport(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
        }
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const entryReportIds = row.entryReportId || this.ids;
      this.$modal.confirm('是否确认删除进场上报编号为"' + entryReportIds + '"的数据项？').then(function() {
        return delEntryReport(entryReportIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('check/entryReport/export', {
        ...this.queryParams
      }, `entryReport_${new Date().getTime()}.xlsx`)
    },

    /** 查询项目报备信息列表 */
    getReportInfoList() {
      this.loading = true;
      selectListreportInfo({}).then(response => {
        this.reportInfoOption = response.data;
        this.loading = false;
      });
    },

    /** 查询部门下拉树结构 */
    // getDeptTree() {
    //   deptUserTreeSelect().then(response => {
    //     this.deptOptions = response.data;
    //   });
    // },

    /** 查询高速路段信息列表 */
    getExpresswaySectionList() {
      this.loading = true;
      selectListExpresswaySection({}).then(response => {
        this.expresswaySectionOption = response.data;
        this.loading = false;
      });
    },

    //获取附件列表
    getFileList(fileLocationName,fileIds,deleteFileId){
      this.form[fileLocationName] = fileIds;
    },

    /** 项目报备单号选项 change事件 */
    handleChange(val){
      //选中的数据和options进行匹配
      var obj={}
      obj= this.reportInfoOption.find(function(i){
        return i.reportInfoId ===val
      });
      this.form.deptId = obj.deptId;
      this.form.deptName = obj.deptName;
      this.form.deptLeader = obj.deptLeader;
      this.form.deptPhone = obj.deptPhone;
    }
  }
};
</script>
